<script setup lang="ts">
// 获取路由
import { onMounted, ref } from 'vue';
// 导入 路由函数
import { useRoute } from 'vue-router';

const title=ref('')
// 获取当前页面对应的路由对象
const route = useRoute()
// console.log(route.query)
// title.value=route.query.key as string 
// onMounted(() => {
//   console.log(route.query);
// })
console.log(route.params)
title.value=route.params.words as string
</script>

<template>
  <div class="search">
    <p>搜索关键字: {{ title }}</p>
    <!-- 直接在html结构中获取路由参数并渲染 -->
    <!-- <p>搜索关键字: {{ $route.query.key }}</p> -->

    <p>搜索关键字: {{ $route.params.words }}</p>
    <p>搜索结果: </p>
    <ul>
      <li>.............</li>
      <li>.............</li>
      <li>.............</li>
      <li>.............</li>
    </ul>
  </div>
</template>

<style>
.search {
  width: 400px;
  height: 240px;
  padding: 0 20px;
  margin: 0 auto;
  border: 2px solid #c4c7ce;
  border-radius: 5px;
}
</style>